const express = require('express')
const { createProxyMiddleware } = require('http-proxy-middleware')
const path = require('path')
const { staticPath, port, proxy } = require('./serverConfig')
const app = express()
/**
 * 这里配置你需要代理的静态资源网页地址，比如目录结构为  html/index.html
 * */
app.use('/', express.static(path.resolve(staticPath)))
/**
 * 配置代理
 * 将html页面的所有请求按照配置，代理转发到目标服务器
 * */
Object.keys(proxy).map(key=>{
    app.use(key, createProxyMiddleware(proxy[key]));
})
app.listen(port, ()=>{
    console.log(`server is running on port ${port}`);
})